package utils;

import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer;
import org.apache.kafka.clients.consumer.ConsumerConfig;

import java.util.Properties;

/**
 * 操作kafka的工具类
 */
public class MykafkaUtil {
    public static  FlinkKafkaConsumer<String> getKafkaSource(String topic,String groupId){
        Properties properties = new Properties();
        properties.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,"hadoop102:9092,hadoop103:9092,hadoop104:9092");
        properties.setProperty(ConsumerConfig.GROUP_ID_CONFIG,groupId);

        FlinkKafkaConsumer<String> kafkasource = new FlinkKafkaConsumer<>(
                topic,
                new SimpleStringSchema(),
                properties
        );
        return kafkasource;


    }


}
